#!/usr/bin/python
#coding: utf-8

import time
from selenium import webdriver

driver = webdriver.Chrome()
first_url = "http://www.baidu.com"
second_url = "http://news.baidu.com"
driver.get(first_url)

try:
	# driver.find_element_by_id("kw").send_keys("selenium")
	# driver.find_element_by_name("wd").send_keys("selenium")
	# driver.find_element_by_class_name("s_ipt").send_keys("selenium")
	# driver.find_element_by_tag_name("input").send_keys("selenium") # WRONG??
	# driver.find_element_by_xpath('//input[@id="kw"]').send_keys("selenium")
	# driver.find_element_by_css_selector("#kw").send_keys("selenium")
	# driver.find_element_by_id("su").click()
	
	# 浏览器最大化显示
	# driver.maximize_window()
	
	# 设置浏览器的宽和高(1000, 800)
	# driver.set_window_size(1000, 800)
	
	print driver.title
	
	time.sleep(3)
	driver.get(second_url)
	print driver.title
	
	# 浏览器的前进和后退
	time.sleep(3)
	driver.back()
	print driver.title
	
	time.sleep(3)
	driver.forward()
	print driver.title
	
	time.sleep(3)
	driver.find_element_by_link_text(u"文库").click()
	print driver.title
	
	# driver.find_element_by_link_text(u"贴吧").click()
except Exception as e:
	print e
finally:
	#import time
	#time.sleep(3)
	# 设置智能等待
	driver.implicitly_wait(3)

driver.quit()
